<?php
    use yii\widgets\Breadcrumbs;
    use yii\bootstrap\Nav;
    use yii\bootstrap\NavBar;
    use frontend\assets\AppAsset;
    use common\widgets\Alert;
    use yii\helpers\ArrayHelper;
    use yii\helpers\Html;
    use yii\grid\GridView;
    /* @var $this yii\web\View */
    /* @var $searchModel common\modules\attendance\models\NewAttendanceSearch */
    /* @var $dataProvider yii\data\ActiveDataProvider */
    $this->title = '查看考勤';
    AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
    <?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div class="wrap">
    <?php
    NavBar::begin([
        'brandLabel' => '今天是'.date('Y-m-d'),
        'brandUrl' => [''],
        'options' => [
            'class' => 'navbar-inverse navbar-fixed-top',
        ],
    ]);
        echo Nav::widget([
        'options' => ['class' => 'navbar-nav navbar-right'],
        'items' => [],
    ]);
    NavBar::end();
    ?>
    <div class="container">
    <div>没有经过大量测试。如果发现错误，请反馈！</div>
    <div class=table-responsive">
        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'columns' => [
                ['class' => 'yii\grid\SerialColumn'],
                'work_date',
                [
                    'attribute'=>'attendance',
                    'label'=>'状态',
                    'value'=>function($model){
                        $attendance=$model::attendance();
                        if(date("Y-m-d")>$model->work_date){
                            if($model->attendance==1 && (empty($model->end_at) or empty($model->start_at))){
                                return $attendance[0];
                            }
                        }
                        return $attendance[$model->attendance];
                    },
                ],
                [
                    'attribute'=>'am_pm',
                    'value'=>function($model){
                        if($model->am_pm==1){
                            return '上午';
                        }
                        return '下午';
                    },
                    'filter'=>[1=>'上午',2=>'下午'],
                ],
                [
                    'attribute'=>'start_at',
                    'label'=>'开始',
                    'value'=>function($model){
                        if($model->start_at){
                            return date('H:i:s',$model->start_at);
                        }
                    }
                ],
                [
                    'attribute'=>'end_at',
                    'label'=>'结束',
                    'value'=>function($model){
                        if($model->end_at){
                            return date('H:i:s',$model->end_at);
                        }
                    }
                ],
                [
                    'attribute'=>'state',
                    'label'=>'报警',
                    'value'=>function($model){
                        if($model->state=='1'){
                            return '报警';
                        }
                    }
                ],
            ],
        ]); ?>
    </div>
    </div>
</div>
<footer class="footer">
    <div class="container">
        <p class="pull-left">&copy; My Company <?= date('Y') ?></p>

        <p class="pull-right"><?= '技术支持：楚源盛互联网事业部' ?></p>
    </div>
</footer>

<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>